package com.zprmb.udzt;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.zprmb.udzt.adapter.DexteritRecordAdapter;
import com.zprmb.udzt.bean.ExOutRecord;
import com.zprmb.udzt.http.AjaxParams;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.VolleryUtil;

public class ExperienceGoldOutRecord extends BaseActivity implements OnClickListener {
	private PullToRefreshListView lv;
	private List<ExOutRecord> list = new ArrayList<ExOutRecord>();
	private DexteritRecordAdapter adapter;
	private ImageView iv_v4_nonetwork;
	private RelativeLayout rl_back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.out_record);
		initView();
		initData();
	}

	private void initData() {
		// TODO Auto-generated method stub
		AjaxParams params = new AjaxParams();
		params.put("pageNo", "1");
		params.put("pageSize", "10");
		VolleryUtil volleryUtil = new VolleryUtil() {

			@Override
			public void onUpDate(JSONObject jsonObject) {
				// TODO Auto-generated method stub
				Log.e("record", jsonObject.toString());
				if (jsonObject.optInt("success") == 1) {
					Gson gson = new Gson();
					JSONObject json1 = jsonObject.optJSONObject("data");
					list = gson.fromJson(json1.optString("resultList"),
							new TypeToken<ArrayList<ExOutRecord>>() {
							}.getType());
					adapter = new DexteritRecordAdapter(ExperienceGoldOutRecord.this,
							list);
					lv.setAdapter(adapter);
					if (list.size() < 1) {
						lv.setVisibility(View.GONE);
						iv_v4_nonetwork.setVisibility(View.VISIBLE);
					} else {
						lv.setVisibility(View.VISIBLE);
						iv_v4_nonetwork.setVisibility(View.GONE);
					}
				}

			}

			@Override
			public void onError() {
				// TODO Auto-generated method stub

			}
		};
		volleryUtil.setHeaders("token", getToken());
		volleryUtil.setRequestMethod(0);
		volleryUtil.setShow(true);
		volleryUtil.execute(ExperienceGoldOutRecord.this, Constant.URL
				+ "/api/v5/experience/listOutAmountDetail?", params.toString());
	}

	private void initView() {
		// TODO Auto-generated method stub
		lv = (PullToRefreshListView) findViewById(R.id.lv_funds_flow);
		rl_back = (RelativeLayout) findViewById(R.id.rl_back);
		iv_v4_nonetwork = (ImageView) findViewById(R.id.iv_v4_nonetwork);
		iv_v4_nonetwork.setOnClickListener(this);
		rl_back.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.rl_back:
			finish();
			break;
		case R.id.iv_v4_nonetwork:
			initData();
			break;
		}

	}

}
